﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using iTextSharp.text;
using iTextSharp.text.pdf;
using Sistema_Totem.Logica.Clases;
using Sistema_Totem.Datos.SqlServer;

namespace Sistema_Totem.Datos.SqlServer
{
    public class _events : PdfPageEventHelper
    {

        protected string titulo;
        SqlServerErs sql = new SqlServerErs();
        protected string versi;
        //protected string nompr = "ProyectoPrueba";
        //protected string codigo = "ers";
        //Proyecto proy = (Proyecto)Session["objProyecto"];

        /// <summary>
        /// Propiedad del itextsharp que te permite crear el header del pdf
        /// </summary>
        public void OnStartPage1(PdfWriter writer, Document document, String nombre)
        {
            string nompr = nombre;
            versi = sql.Version(nompr.ToString());
            PdfPTable table = new PdfPTable(2);
            titulo = sql.SelectTituloPortada(nompr.ToString(), "PORTADA");

            //table.WidthPercentage = 100; //PdfPTable.writeselectedrows below didn't like this
            table.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; //this centers [table]
            //PdfPTable table2 = new PdfPTable(2);

            //////logo
            ////PdfPCell cell2 = new PdfPCell(Image.GetInstance(@"C:\path\to\file.gif"));
            ////cell2.Colspan = 2;
            ////table2.AddCell(cell2);

            ////title
            //PdfPCell cell2 = new PdfPCell(new Phrase("TITLE", new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD | Font.UNDERLINE)));
            //cell2.HorizontalAlignment = Element.ALIGN_CENTER;
            //cell2.Colspan = 2;
            //table2.AddCell(cell2);
            PdfPTable tabla1 = new PdfPTable(2);
            tabla1.TotalWidth = 520f;
            tabla1.LockedWidth = true;
            float[] widthsa = new float[] { 1f, 1f };
            tabla1.SetWidths(widthsa);
            tabla1.HorizontalAlignment = 0;
            tabla1.SpacingBefore = 20f;
            tabla1.SpacingAfter = 20f;
            DateTime fech = DateTime.Now;

            PdfPCell proyectoj = new PdfPCell(new Phrase(titulo.ToString()));
            PdfPCell version = new PdfPCell(new Phrase("Version: " + versi.ToString()));
            PdfPCell software = new PdfPCell(new Phrase("Requerimientos especificos del sistema"));
            PdfPCell fecha = new PdfPCell(new Phrase("fecha:" + fech.ToShortDateString()));
            PdfPCell cod = new PdfPCell(new Phrase("ers"));
            tabla1.AddCell(proyectoj);
            tabla1.AddCell(version);
            tabla1.AddCell(software);
            tabla1.AddCell(fecha);
            cod.Colspan = 2;
            cod.HorizontalAlignment = 0;
            tabla1.AddCell(cod);
            document.Add(tabla1);


            PdfPCell cell = new PdfPCell(tabla1);
            table.AddCell(cell);

            table.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - 36, writer.DirectContent);
        }


    }
}